package com.leetcode.No1800;

/**
 * @program: Solution
 * @description: 最大升序子数组和
 * @author: Wang Zhihua
 * @date: 2022-10-08
 */
public class Solution {
    public int maxAscendingSum(int[] nums) {
        int len = nums.length;
        int ans = 0;
        int idx = 0;
        while(idx < len) {
            int cursum = nums[idx++];
            while(idx < len && nums[idx - 1] < nums[idx]) {
                cursum += nums[idx++];
            }
            ans = Math.max(ans, cursum);
        }
        return ans;
    }

    public static void main(String[] args) {
        Solution solution = new Solution();

        int[] nums = new int[]{10,20,30,5,10,50};
        System.out.println("ans = " + solution.maxAscendingSum(nums));

        nums = new int[]{10,20,30,40,50};
        System.out.println("ans = " + solution.maxAscendingSum(nums));

        nums = new int[]{12,17,15,13,10,11,12};
        System.out.println("ans = " + solution.maxAscendingSum(nums));

        nums = new int[]{100,10,1};
        System.out.println("ans = " + solution.maxAscendingSum(nums));
    }
}
